<template>
<<<<<<< HEAD
	
	<view class="">
		<!-- #ifdef H5 -->
		<view class="login">
			
		
			<input type="text" value="" placeholder="用户名" v-model="username"/>
			<input type="password" value="" placeholder="密码" v-model="password"/>
			<button type="default" @click="login">登录</button>
			</view>
		<!-- #endif -->
		
		<!-- #ifdef MP-WEIXIN -->
		<button type="default" @click="login">登录</button>
		<!-- #endif -->
	</view>
	
</template>

<script>
	import {details} from "../../api/movieList"
	
	export default {
		data() {
			return {
				detailsData:[],
				username: '',
				password: '',
			}
		},
	
		methods: {
			login(){
				let _this = this;
				// #ifdef H5
				wx.request({
				  url: 'http://127.0.0.1:8000/login',
				  method: "post",
				  data: {
				    username:_this.username,
					password:_this.password
				  },
				  success( {data} ) {
					  console.log(data)
					  if(data.code == 200){
						  wx.showToast({ title: "登陆成功" })
						  localStorage.setItem("token",JSON.stringify("token"))
						  // 关闭所有页面并跳转
						  setTimeout(() => {
						  wx.reLaunch({
						    url: '/pages/home/index'
						  })
						  }, 500);
					  } else {
				      wx.showToast({ title: "登录失败" })
				    }
				 
				  }
				})
				// #endif
				
				// #ifdef MP-WEIXIN
				wx.login({
				      success(res) {
						  console.log(res)
				        if (res.code) {
				          //发起网络请求
				          wx.request({
				            url: 'http://127.0.0.1:8000/wxlogin',
				            method: "post",
				            data: {
				              code: res.code
				            },
				            success({ data }) {
				              wx.setStorageSync('token', data.token)
				              wx.setStorageSync('openid', data.openid)
				              if (data.token != "") {
				                wx.showToast({ title: "登陆成功" })
				                // 关闭所有页面并跳转
								setTimeout(() => {
								  
				                wx.reLaunch({
				                  url: '/pages/home/index'
				                })
								
								}, 500);
				              } else {
				                wx.showToast({ title: "登录失败" })
				              }
				
				            }
				          })
				        } else {
				          wx.showToast({ title: "登录失败" })
				        }
				      }
				    })
					// #endif
			}
		},
		created(){
			// #ifdef H5
			if(JSON.parse(localStorage.getItem("token")) != '' && JSON.parse(localStorage.getItem("token")) != null){
				wx.reLaunch({
				  url: '/pages/home/index'
				})
			}
			// #endif
			
			// #ifdef MP-WEIXIN
			if(wx.getStorageSync("token") != '' && wx.getStorageSync("token") != null){
				wx.reLaunch({
				  url: '/pages/home/index'
				})
			}
			// #endif
		}
		
	}
	
	
</script>

<style lang="scss">
	
	.login{
		width: 60%;
		margin:100px auto;
		input{
			border-bottom: 1px solid #ccc;
			padding: 10px;
		}
	}
=======
</template>

<script>
</script>

<style>
>>>>>>> be9f0f7f04b0077acf68c84b06f05daa4947f61b
</style>
